package com.kly.domain.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 用户角色枚举
 * @author admin
 * @date 2025/3/2
 */
@Getter
public enum UserRoleEnum {
    ADMIN("admin", "管理员"),

    USER("user", "普通用户");


    private final String value;

    private final String desc;

    UserRoleEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }


    /**
     * 根据value获取枚举
     * @param value
     * @return
     */
    public static UserRoleEnum getEnumByValue(String value) {
        if (StrUtil.isBlank(value)) {
            return null;
        }
        Map<String, UserRoleEnum> map = Arrays.stream(UserRoleEnum.values())
                .collect(Collectors.toMap(UserRoleEnum::getValue, userRoleEnum -> userRoleEnum));
        return map.getOrDefault(value, null);
    }
}
